//项目
const Sequelize = require('sequelize')
const { mySequelize } = require('../config/index')
const Admin  = require('./Admin') 

const Projects = mySequelize.define('projects', {
  project_id: {
    type: Sequelize.INTEGER(11),
    allowNull: false,
    primaryKey: true,
    autoIncrement: true,
  },
  admin_id: {
    type: Sequelize.INTEGER(11),
    allowNull: false,
    foreignKey: true,
  },
  title: {
    type: Sequelize.STRING,
    allowNull: false,
    unique: true,
  },
  info: {
    type: Sequelize.TEXT,
    allowNull: false,
  },
  categorization: {
    type: Sequelize.INTEGER,
    allowNull: false,
    comment: "0全体，1计院，2理学院，3管院，4医学院...因为全校20个专业，数量较多，列举四个进行示例开发",
  },
  people_num: {
    type: Sequelize.INTEGER,
    allowNull: false,
  },
  start_time: {
    type: Sequelize.DATE,
    allowNull: false,
  },
  over_time: {
    type: Sequelize.DATE,
    allowNull: false,
  },
  status: {
    type: Sequelize.INTEGER,
    allowNull: false,
    comment: "0-进行中,1-结束",
  },
}, {
  freezeTableName: true,
  timestamps: false,
  tableName: 'projects',
})

//Projects.sync({ force: true })

// 关联关系
Projects.belongsTo(Admin, {
  foreignKey: 'admin_id', // `Projects` 表中的外键
  targetKey: 'admin_id', // `Admin` 表中的主键
  as: 'adminInfo' // 定义别名，便于联表查询时使用
});

module.exports = Projects